package com.masterclient.app.modules.shop.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.baselibrary.bean.shop.DealerProductManagerData;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselib.container.CommonBaseResponse;
import com.eoner.commonbean.product.ShareProductDataBean;
import com.masterclient.app.httpservice.RetrofitUtil2;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * @auther hjian
 * @date 2020/9/11.
 */
public class DealerProductManagerPresenter extends DealerProductManagerContract.Presenter {
    @Override
    public void getProductList(String status, int page, String special_product_type) {
        mRxManager.add(toSubscribe(RetrofitUtil2.getInstance().getDealerProductList(status,page+"","15",special_product_type), new Consumer<CommonBaseResponse<DealerProductManagerData>>() {
            @Override
            public void accept(@NonNull CommonBaseResponse<DealerProductManagerData> bean) throws Exception {
                if(bean.getCode() == 0){
                    mView.showData(bean.getData());
                }else {
                    mView.showDataFailed(bean.getMsg());
                }
            }
        },new ThrowableConsumer() {
            @Override
            public void accept(Throwable o) throws Exception {
                mView.showDataFailed("网络异常，请重试");
                super.accept(o);
            }
        }));
    }

    @Override
    public void getProductShare(String product_id) {
        mRxManager.add(toSubscribe(RetrofitUtil2.getInstance().productShare(product_id), new Consumer<CommonBaseResponse<ShareProductDataBean>>() {
            @Override
            public void accept(CommonBaseResponse<ShareProductDataBean> bean) throws Exception {
                if (bean.getCode()==0){
                    mView.showShareData(true,bean.getData());
                }else {
                    mView.showShareData(false,null);
                    ToastUtil.showToast(bean.getMsg());
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.showShareData(false,null);
                ToastUtil.showToast("网络异常，请重试");
            }
        }));
    }
}
